# @Time    : 2025-08-14 16:46
# @Author: Fioman
# @Phone  : 13149920693
# @Tips      : Talk is cheap,show me the code ^_^
import paddlex
import importlib.metadata
import argparse
import subprocess
import sys

pyinstaller_filename = "main.py"

user_deps = [dist.metadata["Name"] for dist in importlib.metadata.distributions()]
deps_all = list(paddlex.utils.deps.DEP_SPECS.keys())
deps_need = [dep for dep in user_deps if dep in deps_all]

cmd = [
    "pyinstaller", pyinstaller_filename,
    "--noconfirm",        # 添加 --noconfirm 参数
    "--windowed",         # 添加 --windowed 参数（不显示控制台窗口）
    "--name", "测试助手",  # 设置应用名称为中文
    "--icon", "icon.ico",  # 设置应用图标
    "--collect-data", "paddlex",
    "--collect-binaries", "paddle"
]


for dep in deps_need:
    cmd += ["--copy-metadata", dep]

print("PyInstaller command:", " ".join(cmd))

try:
    result = subprocess.run(cmd, check=True)
except subprocess.CalledProcessError as e:
    print("Installation failed:", e)
    sys.exit(1)